import { model, Schema, Types } from "mongoose";
import { MethodList, Permission } from "@/types/admin/permission";

const PermissionSchema = new Schema<Permission>(
    {
        name: { type: String, required: true },
        key: { type: String, required: true, unique: true },
        status: { type: Boolean, default: true },
        desc: { type: String },
        type: { type: String, required: true },
        path: { type: String },
        label: { type: String },
        component: { type: String },
        icon: { type: String },
        method: { type: String, enum: MethodList },
        children: { type: [Types.ObjectId] },
        sort: { type: Number, default: 100 }
    },
    { timestamps: { createdAt: true, updatedAt: true } }
);

export const PermissionModel = model("Permission", PermissionSchema, "permissions");
